<!--计算电费-->
<div class="modal fade" id="jisuandianfei" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">计算电费</h4>
      </div>
      <div class="modal-body">
          <form id="myform2">
           <div class="form-group input-group col-md-12">
         <span class="input-group-addon">上个月电费</span>
         <input type="text"  class="form-control" readonly="readonly"  name="predushu" placeholder="上个月电费">
      </div>
              
              <div class="form-group input-group col-md-12">
         <span class="input-group-addon">这个月电度数</span>
         <input type="text"  class="form-control"   name="dushu" placeholder="这个月电度数">
      </div>
              
      <div class="form-group input-group col-md-12">
         <span class="input-group-addon">每度价格</span>
         <input type="text"  class="form-control"   name="dushujiage" value="<{$dianfare}>" placeholder="每度价格">
      </div>
              
              
          </form>
          
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" id="btnjisuandianfei">计算</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<!--end计算电费-->
<script>
    $('#jisuandianfei').on('show.bs.modal', function (event){
    var button = $(event.relatedTarget);
    
    var inputname=button.data("inputname");
    $("input[name='predushu']").val($("input[name='predian_du']").val());
    $("input[name='dushu']").val($("input[name='dian_du']").val());
    if(inputname){
    $("#btnjisuandianfei").data("inputname",inputname);
   }

});
$('#jisuandianfei').on('hidden.bs.modal', function (e) {
    var inputname=$("#btnjisuandianfei").data("inputname");
    if(inputname){
    $("input[name='"+inputname+"']").focus();
}
});
$("#btnjisuandianfei").click(function(){
        var dushu=$("input[name='dushu']").val();
        var predushu=$("input[name='predushu']").val();
        var inputname=$(this).data("inputname");
        var dushujiage=$("input[name='dushujiage']").val();
        if(isNaN(dushu)){
            alert("电度数请输入数字");
            $("input[name='dushu']").focus();
            return false;
        }
        if(isNaN(dushujiage)){
            alert("每度价格请输入数字");
            $("input[name='dushujiage']").focus();
            return false;
        }
        if(dushu-predushu<0){
            alert("电度数为负数");
            $("input[name='dushu']").focus();
            return false;
        }
        var zj=(dushu-predushu)*dushujiage;
        
        $("input[name='"+inputname+"']").val(zj.toFixed(2));
        $("#jisuandianfei").modal('hide');
        $("input[name='"+inputname+"']").focus();
    });
    $("input[name='dushu']").blur(function(){
        $("input[name='dian_du']").val($(this).val());
    });
</script>